#include <math.h>
#include <stdio.h>
#include <stdlib.h>

#include "testutils.h"
#include "rngs.h"

void init_test_data(struct gameState *state, int num_players)
{
	int i;

	state->coins = 0;
	state->numActions = 1;
	state->numBuys = 1;
	state->numPlayers = num_players;
	state->outpostPlayed = 0;
	state->outpostTurn = 0;
	state->playedCardCount = 0;
	state->whoseTurn = 0;

	for (i = 0; i < num_players; i++) {
		state->deckCount[i] = 0;
		state->discardCount[i] = 0;
		state->handCount[i] = 0;
	}

	for (i = 0; i < 27; i++) {
		state->supplyCount[i] = 10;
		state->embargoTokens[i] = 0;
	}
}

/*
 * Generates a psuedorandom card with a 25% chance of it being a coin
 */
int random_card(void)
{
	int type = rand() % 4;
	int coin_type;
	if (type == 0) {
		coin_type = rand() % 3;
		return (coin_type == 0)
			? copper : (coin_type == 1)
			? silver : gold;
	}

	// Could still give back a coin, but eh
	return rand() % 27;
}

/*
	Generates a psuedorandom Kingdom Card.
	*/
int random_kcard(void)
{
	int card = rand() % 27;
	return (card < 7) ? card + 7 : card;
}

int treasure_count(int card_collection[], int size)
{
	int i;
	int count = 0;

	for (i = 0; i < size; i++) {
		if (card_collection[i] == copper || card_collection[i] == silver || card_collection[i] == gold) {
			count++;
		}
	}

	return count;
}

int contains_card(int card_collection[], int card, int size)
{
	int i;

	for (i = 0; i < size; i++) {
		if (card_collection[i] == card) {
			return 1;
		}
	}

	return 0;
}

int card_count(int card_collection[], int card, int size)
{
	int i;
	int count = 0;

	for (i = 0; i < size; i++) {
		if (card_collection[i] == card) {
			count++;
		}
	}

	return count;
}